package com.aaa.system.controller.api;

import com.aaa.entity.DictData;
import com.aaa.entity.DictType;
import com.aaa.system.aop.annotation.Log;
import com.aaa.system.service.IDictDataService;
import com.aaa.system.service.IDictTypeService;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.stream.events.DTD;
import java.util.Arrays;
import java.util.List;

/**
 * 响应到前端的controller类
 */
@RestController
@RequestMapping("system/api/dict/type")
public class ApiDictTypeController {

    @Autowired
    private IDictTypeService dictTypeService;


    /**
     * 分页动态查询所有字典类型数据
     * @param current  当前页码
     * @param size    每页显示几条数据
     * @param dictType 模糊查询条件
     * @return
     */
    @PostMapping("selectAll/{current}/{size}")
    public Result<IPage<DictType>> selectAll(
            @PathVariable Integer current,
            @PathVariable Integer size,
            @RequestBody DictType dictType
    ){
        Result<IPage<DictType>> selectAll = dictTypeService.selectAll(current,size,dictType);
        return selectAll;
    }


    /**
     * 添加或者修改字典类型数据
     * @param dictType  字典类型实体数据
     * @return
     */
    @Log(title = "添加/修改字典类型数据",business_type = "1")
    @PostMapping("saveOrUpdateDictType")
    public Result<Boolean> saveOrUpdateDictType(@RequestBody DictType dictType){
        return dictTypeService.saveOrUpdateDictType(dictType);
    }


    /**
     * 根据id删除单个或者多个字典类型数据
     * @param dictIds
     * @return
     */
    @Log(title = "删除字典类型数据",business_type = "3")
    @DeleteMapping("deleteDictTypeByIds/{dictIds}")
    public Result<Boolean> deleteDictTypeByIds(@PathVariable Long[] dictIds){
        return dictTypeService.deleteDictTypeByIds(dictIds);
    }

    /**
     * 不分页对所有字典类型进行查询，用于字典数据界面的模糊查询下拉列表展示
     * @return
     */
    @GetMapping("list")
    public Result<List<DictType>> list(){
        Result<List<DictType>> list = dictTypeService.dictTypeList();
        return list;
    }

    /**
     * 根据请求路径中的字典类型id 查询 该字典类型对应的字典类型对象中的字典类别
     * @param dictId 字典类型id
     * @return  字典类型中的字典类别字段
     */
    @PostMapping("getTypeById/{dictId}")
    public Result<String> getTypeById(@PathVariable Long dictId){
        Result<String> getTypeById = dictTypeService.getTypeById(dictId);
        return getTypeById;
    }
}
